<template>
  <div>
    <el-container>
      <el-header>
        <div  class="firstSytle">
          <el-button size="mini" type="success" @click="initData"   icon="el-icon-refresh">刷新</el-button>
        </div>
      </el-header>

      <el-main style="padding-left: 1px;padding-top: 0px;height:100%">
        <div>
          <el-table :data="repairs" stripe v-loading="tableLoading" size="mini" style="width: 100%;">
            <el-table-column prop="listId" label="序号" width="80px" align="center"></el-table-column>
            <el-table-column prop="buildId" label="公寓编号" width="120px"></el-table-column>
            <el-table-column prop="roomId" label="宿舍号" width="120px"></el-table-column>
            <el-table-column prop="description" label="报修描述" width="200px"></el-table-column>
            <el-table-column prop="applicant" label="报修人" width="120px"></el-table-column>
            <el-table-column prop="time" label="报修时间" width="180px"></el-table-column>
            <el-table-column prop="operator" label="维修人员" width="180px"></el-table-column>
            <el-table-column prop="status" label="维修状态" width="120px"></el-table-column>
            <el-table-column prop="flag" label="审核状态" width="120px"></el-table-column>
            <el-table-column prop="result" label="维修结果" width="120px"></el-table-column>
            <el-table-column prop="endTime" label="维修时间" width="180px"></el-table-column>
          </el-table>
          <div class="lastLine" style="margin-top: 10px">               
            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                           :current-page.sync="pageNum" :page-sizes="[10, 20,30,50,100,200,]"
                           :page-size="pageSize"
                           layout="sizes, prev, pager, next" :total="total">      
            </el-pagination>
          </div>
        </div>
      </el-main>
    </el-container>
  </div>

</template>

<script>
    export default {
        data() {
            return {
                repair: {
                    buildId:'',
                    roomId: '',
                    description: '',
                    applicant: '',
                    operator: '',
                    status: '',
                    endTime: '',
                    time: '',
                },
                repairs: [],
                tableLoading: false,
                pageNum: 1,
                pageSize: 10,
                total: 0,
                list: [],
            };
        },
        methods: {
            initData: function () {
                this.tableLoading = true;
                var tempdate
                // var _this = this;
                this.getRequest("/repair/rep/repair/record?pageSize=" + this.pageSize + "&pageNum=" + this.pageNum).then(resp => {
                    this.tableLoading = false;
                    if (resp && resp.status == 200) {
                        this.total = resp.data.obj.total;
                        this.repairs = resp.data.obj.data;
                        for (var i = 0; i < this.repairs.length; i++) {
                            this.repairs[i].listId = i + 1
                            tempdate =this.repairs[i].time
                            this.repairs[i].time=tempdate.slice(0,tempdate.indexOf("."))
                            switch (this.repairs[i].status) {
                                case 0:
                                    this.repairs[i].status = '待维修';
                                    break;
                                case 1:
                                    this.repairs[i].status = '已维修';
                                    break;
                            }
                            switch (this.repairs[i].flag) {
                                case 0:
                                    this.repairs[i].flag = '待审核';
                                    break;
                                case 1:
                                    this.repairs[i].flag = '已审核';
                                    break;
                            }
                            switch (this.repairs[i].result) {
                                case 0:
                                    this.repairs[i].result = '未解决';
                                    break;
                                case 1:
                                    this.repairs[i].result = '已解决';
                                    break;
                            }
                        }
                    }
                })
            },
            handleSizeChange(val) {    //分页
                this.pageSize = val;
                this.initData()
            },
            handleCurrentChange(val) {   //分页
                this.pageNum = val;
                this.initData()
            },

        },
        mounted: function () {
            this.initData();
        },

    }
</script>

<style scoped>
  .firstSytle {
    margin-top: 30px;
    width: 100%;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
  }
  .lastLine {
    display:  flex;
    flex-direction:  row;
    justify-content:  flex-end;
    margin:  10px 0 10px 0;
  }

  .el-row {
    margin: 10px 0;
  }

  .el-table {
    text-align: left;
  }

</style>
